<?php

header('Content-Type: text/html; charset=UTF-8');

/*连接数据库通用代码*/
$domain = get_domain();
$ip = getenv('HTTP_BAE_ENV_ADDR_SQL_IP');
$port = getenv('HTTP_BAE_ENV_ADDR_SQL_PORT');
$username = getenv('HTTP_BAE_ENV_AK');
$password = getenv('HTTP_BAE_ENV_SK');
if($domain == 'localhost' || $domain == 'alikangkang.com'){
    define('DB_NAME', 'zyk_cai');
    define('DB_USER', 'root');
    define('DB_PASSWORD', 'root');
    define('DB_HOST', 'localhost');
}elseif($domain == 'duapp.com'){
    /*上线后改正*/
    define('DB_NAME', 'BNUTUDcdosnKFXCtaXUq');
    define('DB_USER', $username);
    define('DB_PASSWORD', $password);
    define('DB_HOST', $ip.':'.$port);
}
$con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD); 
mysql_select_db(DB_NAME,$con);
mysql_query("SET NAMES utf8");

$programeArr = array('app梦工厂微博','YiBo.Android版');
$c_c=count($programeArr)-1;
$i=rand(0,$c_c);
$programe = $programeArr[$i];

$userName = '最烂IT论坛';
$sql="select * from cai_appkey where sns = 'weibo' and type='v1' and name = '".$programe."'"; 
$result = mysql_query($sql);
while($row=mysql_fetch_array($result)){
    $wb_akey = $row['key_key'];
    $wb_skey = $row['value_value'];
    $sns_id = $row['id'];
}
define('WB_AKEY',$wb_akey);
define('WB_SKEY',$wb_skey);
define('SNS_ID',$sns_id);






/*功能函数*/
function dump($vars, $label = '', $return = false) {
    if (ini_get('html_errors')) {
        $content = "<pre>\n";
        if ($label != '') {
            $content .= "<strong>{$label} :</strong>\n";
        }
        $content .= htmlspecialchars(print_r($vars, true));
        $content .= "\n</pre>\n";
    } else {
        $content = $label . " :\n" . print_r($vars, true);
    }
    if ($return) { return $content; }
    echo $content;
    return null;
}
function get_domain(){
    $host=$_SERVER['HTTP_HOST'];
    $host=strtolower($host);
    if(strpos($host,'/')!==false){
        $parse = @parse_url($host);
        $host = $parse['host'];
    }
    $topleveldomaindb=array('com','edu','gov','int','mil','net','org','biz','info','pro','name','museum','coop','aero','xxx','idv','mobi','cc','me');
    $str='';
    foreach($topleveldomaindb as $v){
        $str.=($str ? '|' : '').$v;
    }
    $matchstr="[^\.]+\.(?:(".$str.")|\w{2}|((".$str.")\.\w{2}))$";
    if(preg_match("/".$matchstr."/ies",$host,$matchs)){
        $domain=$matchs['0'];
    }else{
        $domain=$host;
    }
    /*if($domain == 'duapp.com'){
        $host=$_SERVER['HTTP_HOST'];
        $domain=strtolower($host);
    }*/
    return $domain;
}

?>
